import axios from 'axios'
import { CONFIG } from './config'

// 获取商品主分类
export function getMainType(options) {
  const url = 'shop/public/commodity/getMainType'
  const data = {
    type: options.type,
    shopCode: options.shopCode
  }
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 获取商品子分类
export function getSubType(options) {
  const url = 'shop/public/commodity/getSubType'
  const data = {
    type: options.type,
    shopCode: options.shopCode,
    superiorId: options.superiorId || '',
    subIds: options.subIds || ''
  }
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 获取商品列表
export function getShopCommodityList(options) {
  const url = 'shop/public/commodity/ShopCommodityList'
  const data = {
    shopCode: options.shopCode,
    salesStatus: options.salesStatus,
    name: options.name || '',
    commodityMianId: options.commodityMianId || null,
    commoditySubId: options.commoditySubId || null,
    customCategoryId: options.customCategoryId || null,
    barcode: options.barcode || null,
    pageSize: options.pageSize || 6,
    pageNo: options.pageNo || 1
  }
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 获取商户联系人信息（判断是否为商户端）
export function getMerchantUserMsg(options) {
  const url = 'shop/public/shopMerchant/getMerchantUserMsg'
  const data = {
    merchantId: options.merchantId || null,
    phone: options.phone,
    shopCode: options.shopCode || null
  }
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}